package com.jianqiao.delivery.pay.service.impl;

import org.springframework.stereotype.Component;
import javax.net.ssl.SSLContext;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;

import java.io.File;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;

/**
 * author: cyx
 * create: 2024/11/23 16:31
 **/
//@Component
public class SSLConfig {

    public void load() throws UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, KeyManagementException {
        SSLContext sslcontext = SSLContexts.custom()
                .loadKeyMaterial(new File("C:\\Users\\os\\Desktop\\VISA材料\\第二自建\\visa.p12"), "ptjq12345".toCharArray(),
                        "ptjq12345".toCharArray())
                .loadTrustMaterial(new File("C:\\Users\\os\\Desktop\\VISA材料\\第二自建\\visa.p12"), "ptjq12345".toCharArray())
                .build();

// Allow TLSv1.2 protocol only
        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1.2" }, null,
                SSLConnectionSocketFactory.getDefaultHostnameVerifier());

        CloseableHttpClient httpClient = HttpClients.custom()
                .setSSLSocketFactory(sslSocketFactory).build();
    }
}
